clear
set mem 1g
set more off
prog drop _all
capture log close

pause off

	local graph1_options "ms(T) mc(black) mfc(black) c(l) lp(shortdash) lc(black)  lwidth(1.2)"
	local graph2_options "ms(O) mc(green) mfc(green) c(l) lp(dash_dot) lc(green)   lwidth(1.2)"
	local graph3_options "ms(T) mc(blue) mfc(none) c(l)   lp(longdash) lc(blue)   lwidth(1.2)"
	local graph4_options "ms(D) mc(red) mfc(red) c(l)     lp(solid) lc(red)   lwidth(1.2)"
	local graph5_options "ms(D) mc(red) mfc(none) c(l) lp(dash) lc(red)"
	local graph6_options "ms(O) mc(green) mfc(none) c(l) lp(dash) lc(green)"


set scheme s1color

****************************************************************
use out_files/sim_model_part1, clear
gen hgc13more = (educ>=13)

foreach var in hgc13more dq {

	sum `var' if age == 30
	global G`var' = `r(mean)'
	local _`var'_fitted = `r(mean)'
	
	sum `var' if age == 30 & (addiction + dq)>=1
	global Gever`var' = `r(mean)'
	local _ever`var'_fitted  = `r(mean)'
}

** fitted model
disp $Ghgc13more
disp $Gdq


*** read: subsidizing schooling 

insheet everdq igrid taxrate_dq cbc_sub gtr_sub gtr_csub dq hgc hgc12more hgc11less hgc12 hgc1315 hgc16more using out_files_optTax/ALL_outcomes.txt, clear	
gen hgc13more =  hgc1315 + hgc16more
drop if taxrate_dq == 0 

saveold data_opttax, replace



*** read: subsidizing at-risk population
insheet everdq igrid taxrate_dq cbc_sub gtr_sub gtr_csub dq hgc hgc12more hgc11less hgc12 hgc1315 hgc16more using out_files_optTax1/ALL_outcomes.txt, clear	
gen hgc13more =  hgc1315 + hgc16more
drop if taxrate_dq == 0 

rename * model1_*
rename model1_taxrate_dq taxrate_dq
rename model1_everdq     everdq 

merge 1:1 everdq taxrate_dq using data_opttax
keep if _merge == 3
assert _merge == 3
drop _merge
saveold data_opttax, replace



*** read: subsidizing non-smokers
insheet everdq igrid taxrate_dq cbc_sub gtr_sub gtr_csub dq hgc hgc12more hgc11less hgc12 hgc1315 hgc16more using out_files_optTax2/ALL_outcomes.txt, clear	
gen hgc13more =  hgc1315 + hgc16more
drop if taxrate_dq == 0 

rename * model2_*
rename model2_taxrate_dq taxrate_dq
rename model2_everdq     everdq 
merge 1:1 everdq taxrate_dq using data_opttax
keep if _merge == 3
assert _merge == 3
drop _merge
saveold data_opttax, replace


global dir_tax optTax
	
****************************************************************
global educTarget          hgc13more
global evereducBenchmark   $Geverhgc13more 
global evereducNodq        $Geverhgc13more_nodq
global educBenchmark   		$Ghgc13more 
global educNodq        		$Ghgc13more_nodq
local  educTarget          $educTarget  
****************************************************************


	foreach var of varlist `educTarget' model1_`educTarget'  model2_`educTarget' {
		
		gen chg`var' = . 
		replace chg`var' = `var' - $educBenchmark if everdq == 0
		replace chg`var' = `var' - $evereducBenchmark if everdq == 1
				
	}
	label var chg`educTarget'        "subsidizing schooling"	
	label var chgmodel1_`educTarget' "subsidizing at risk population"	
	label var chgmodel2_`educTarget' "subsidizing non-smokers"	

    graph bar (asis) chg`educTarget' chgmodel1_`educTarget' chgmodel2_`educTarget' if everdq == 1, bar(1, color(purple) fintensity(inten100)) bar(2, color(purple) fintensity(inten60)) bar(3, color(purple) fintensity(inten20)) bargap(10) scheme(s1color) ysc(titlegap(2)) ylabel(, grid) ytitle(Changes in college attendance rate) asyvars blabel(bar, position(inside) format(%9.3f) color(white))
	graph export out_figs_optTax/figchg_ever`educTarget'_allModels.pdf, as(pdf) replace 
	graph export out_figs_optTax/figchg_ever`educTarget'_allModels.eps, as(eps) replace 
		
	graph export ../outputs/Figure_09a.pdf, as(pdf) replace 
	graph export ../outputs/Figure_09a.eps, as(eps) replace
	
	
	foreach var of varlist dq model1_dq model2_dq {
		gen chg`var' = `var' - $Gdq 
	}
	label var chgdq        "subsidizing schooling"	
	label var chgmodel1_dq "subsidizing at risk population"	
	label var chgmodel2_dq "subsidizing non-smokers"	

    graph bar (asis) chgdq chgmodel1_dq chgmodel2_dq if everdq == 0,                                bar(1, color(green) fintensity(inten100)) bar(2, color(green) fintensity(inten60)) bar(3, color(green) fintensity(inten20)) bargap(10) scheme(s1color) ysc(titlegap(2)) ylabel(, grid) ytitle(Changes in age-30 smoking rate) asyvars blabel(bar, position(inside) format(%9.3f) color(white))
	graph export out_figs_optTax/figchg_dqa30_allModels.pdf, as(pdf) replace 
	graph export out_figs_optTax/figchg_dqa30_allModels.eps, as(eps) replace 
	
	graph export ../outputs/Figure_09b.pdf, as(pdf) replace 
	graph export ../outputs/Figure_09b.eps, as(eps) replace



!rm data_opttax.dta 

***************************************************************

capture log close

